<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>08表格删除案例</title>
</head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .wrap {
            width: 410px;
            margin: 100px auto;
        }
        table {
            border-collapse: collapse;
            border-spacing: 0;
            border: 1px solid #c0c0c0;
        }
        th,td { 
            border: 1px solid #d0d0d0;
            color: #404060;
            padding: 10px;
        }
        th {
            background-color: #09c;
            font: bold 16px "微软雅黑";
            color: #fff;
        }
        td {
            font: 14px "微软雅黑";
        }
        tbody tr {
            background-color: #f0f0f0;
        }
        td a.get {
                text-decoration: none;
        }
    </style>
<body>
    <div class="wrap">
        <input type="button" value="清空内容" id="btnEmpty">
        <input type="button" value="添加" id="btnAdd">
        <table>
            <thead>
                <tr>
                    <th>课程名称</th>
                    <th>所属学院</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody id="j_tb">
                <tr>
                    <td>JavaScript</td>
                    <td>哈哈哈哈-前端与移动开发学院</td>
                    <td><a href="#" class="get">DELETE</a></td>
                </tr>
                <tr>
                    <td>css</td>
                    <td>哈哈哈哈-前端与移动开发学院</td>
                    <td><a href="#" class="get">DELETE</a></td>
                </tr>
                <tr>
                    <td>html</td>
                    <td>哈哈哈哈-前端与移动开发学院</td>
                    <td><a href="#" class="get">DELETE</a></td>
                </tr>
                <tr>
                    <td>jQuery</td>
                    <td>哈哈哈哈-前端与移动开发学院</td>
                    <td><a href="#" class="get">DELETE</a></td>
                </tr>
            </tbody>
        </table>
    </div>


    <script src="../jquery-3.2.1.js"></script>
    <script>
        $(function(){
            $("#btnEmpty").on("click",function(){
                $("#j_tb").empty();     // 清空按钮 清空body
            });

            // $(".get").on("click",function(){
            //     $(this).parent().parent().remove();
            // });
            $("#j_tb").on("click",".get", function(){
                $(this).parent().parent().remove();
            });

            $("#btnAdd").on("click",function(){
                $('<tr><td>bootstrap</td><td>啦啦啦-前端与移动开发学院</td><td><a href="#" class="get">DELETE</a></td></tr>')
                .appendTo("#j_tb");
            })
        })
    
    </script>
</body>
</html>